package org.example.sbdemo.config;

import org.example.sbdemo.response.Response;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(IllegalArgumentException.class)
    public Response<Void> handleIllegalArgument(IllegalArgumentException ex) {
        return Response.newError(ex.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public Response<Void> handleException(Exception ex) {
        String msg = ex.getMessage() == null ? "Internal server error" : ex.getMessage();
        return Response.newError(msg);
    }
}
